﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AddressBook.DAO;
using AddressBook.Entity;
using System.Text;

public partial class GetContactInfo : System.Web.UI.Page
{
    static Base_EmployeeDAO dao = new Base_EmployeeDAO();

    protected void Page_Load(object sender, EventArgs e)
    {
        ////TODO EmployID 不能重复，备份到主服务器上后
        ResultEntity result = new ResultEntity();
        result.Name = "ContactInfo";

        if (!string.IsNullOrEmpty(Request.QueryString["contactid"]))
        {
            Guid employeeid ;
            if (Guid.TryParse(Request.QueryString["contactid"], out employeeid))
            {
                Base_Employee employ = dao.GetInfoByKey(employeeid);
                if (employ != null)
                {
                    if (!employ.isDelete)
                    {
                        result.ResultCode = "0";
                        StringBuilder sb = new StringBuilder();
                        sb.Append("{");
                        sb.AppendFormat("\"EmployID\":\"{0}\",", employ.EmployID);
                        sb.AppendFormat("\"FstName\":\"{0}\",", employ.FstName);
                        sb.AppendFormat("\"SecName\":\"{0}\",", employ.SecName);
                        sb.AppendFormat("\"Phone\":\"{0}\",", employ.Phone);
                        sb.AppendFormat("\"DeptID\":\"{0}\",", employ.DeptID);
                        sb.AppendFormat("\"Address\":\"{0}\",", employ.Address);
                        sb.AppendFormat("\"Email\":\"{0}\",", employ.Email);
                        sb.AppendFormat("\"FamiryTel\":\"{0}\",", employ.FamiryTel);
                        sb.AppendFormat("\"Fax\":\"{0}\",", employ.Fax);
                        sb.AppendFormat("\"HeadUrl\":\"{0}\",", employ.HeadUrl);
                        sb.AppendFormat("\"Sex\":\"{0}\",", employ.Sex);
                        sb.AppendFormat("\"Station\":\"{0}\",", employ.Station);
                        sb.AppendFormat("\"Tel\":\"{0}\"", employ.Tel);
                        sb.Append("}");

                        result.Contents = sb.ToString();
                    }
                    else
                    {
                        result.Desc = "用户已被删除！";
                        result.ResultCode = "-1";
                    }
                }
                else
                {
                    result.Desc = "用户不存在！";
                    result.ResultCode = "-1";
                }
            }
            else
            {
                result.Desc = "参数不正确！";
                result.ResultCode = "-2";
            }
        }
        else
        {
            result.Desc = "参数不正确！";
            result.ResultCode = "-2";
        }

        Response.Write(Common.ReturnResult(result));
    }
}